import * as types from './mutation_types'

const mutations = {
  [types.REFRESH_WINDOW_SIZE](state) {
    const { windowSize } = state
    windowSize.clientWidth = document.body.clientWidth || 1280
    windowSize.clientHeight = document.body.clientHeight || 900
    //
    if (windowSize.clientWidth < 1280) {
      state.uiSize = 'default'
    } else if (state.windowSize.clientWidth < 1600) {
      state.uiSize = 'default'
    } else {
      state.uiSize = 'large'
    }
    //
    const leftWrapper = document.querySelector('.cui-left-wrapper')
    if (leftWrapper) {
      windowSize.bodyWidth = windowSize.clientWidth - leftWrapper.clientWidth
    } else {
      windowSize.bodyWidth = windowSize.clientWidth
    }
    //
    const topWrapper = document.querySelector('.cui-top-wrapper')
    if (topWrapper) {
      windowSize.bodyHeight = windowSize.clientHeight - topWrapper.clientHeight
    } else {
      windowSize.bodyHeight = windowSize.clientHeight - 64
    }
  },
  [types.OPEN_PAGE](state, event) {
    state.pageEvent = event
  },
  [types.DO_ACTION_SUCCESS](state, event) {
    state.actionSuccessEvent = event
  },
  [types.DO_ACTION_END](state, event) {
    state.actionEndEvent = event
  },
}

export default mutations
